﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyGeneration.dOOdads;

namespace ShopOnline.Controls
{
    public delegate void NeedDataSourceEventHandler(object sender, EventArgs e);

    public partial class BaseDataListCtrl : BaseControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public string CSSClass
        {
            get { return datalist.CssClass; }
            set { datalist.CssClass = value; }
        }

        public Unit Width
        {
            get { return datalist.Width; }
            set { datalist.Width = value; }
        }

        public Unit Height
        {
            get { return datalist.Height; }
            set { datalist.Height = value; }
        }

        public int RepeatedColumns
        {
            get { return datalist.RepeatColumns; }
            set { datalist.RepeatColumns = value; }
        }

        public RepeatLayout RepeatLayout
        {
            get { return datalist.RepeatLayout; }
            set { datalist.RepeatLayout = value; }
        }

        public RepeatDirection RepeatDirection
        {
            get { return datalist.RepeatDirection; }
            set { datalist.RepeatDirection = value; }
        }

        public int PageSize
        {
            get;
            set;
        }

        public int TotalPage
        {
            get;
            set;
        }

        public int CurrentPageIndex
        {
            get;
            set;
        }

        public event NeedDataSourceEventHandler NeedDataSource;
        private void OnNeedDataSource(EventArgs e)
        {
            if (NeedDataSource != null)
            {
                NeedDataSource(this, e);
            }

            datalist.DataBind();
        }

        public virtual void Rebind()
        {
            EventArgs e = new EventArgs();
            OnNeedDataSource(e);
        }

        public bool AllowPaging
        {
            get;
            set;
        }

        public Object DataSource
        {
            get { return datalist.DataSource; }
            set { datalist.DataSource = value;}
        }

        public DataKeyCollection DataKeys
        {
            get { return datalist.DataKeys;  }
        }

        public TableItemStyle AlternatingItemStyle
        {
            get { return datalist.AlternatingItemStyle; }
        }

        public TableItemStyle ItemStyle
        {
            get { return datalist.ItemStyle; }
        }
    }
}